Installing the New Features
Learn About Amazon VGT2 Learning Manager Chanci Turner
If you have previously set up the Neptune workbench, simply stop and restart your Jupyter notebook on the Amazon SageMaker console to access the new features. For those who have not yet installed the workbench, launching a new notebook via the Amazon Neptune console will do the trick. This update includes two new example notebooks that provide a detailed overview of the new functionalities for both Gremlin and SPARQL queries. For comprehensive installation guidance, refer to the following resources:
- Using the Neptune Workbench with Jupyter Notebooks
- Using Neptune’s Getting Started notebooks
- Graph visualization in the Neptune workbench
After updating the workbench, verify the version number using the command %graph_notebook_version
. You should see version 1.27 or higher. Additionally, it’s wise to ensure your connection to the Neptune server is functioning properly with the %status
command.
Loading Sample Data
The Neptune workbench offers a %seed
command to load the sample data needed for the queries discussed here. Create a new cell in your notebook, type in %seed
, and execute the cell. You will be prompted to select your Language (graph type) and Data set. To follow along with all examples, install both the Gremlin and SPARQL datasets, selecting “airports” for the Data set. After clicking Submit, the data will load in just a few seconds.
Visual Representation of Gremlin Queries
The property graph data loaded by the %seed
command models the global air route network, featuring vertices for airports, countries, and continents. Edges connect airports and link countries and continents to airports. Each airport possesses various properties, with edges between them denoting the distance in miles.
You can find the dataset in the GitHub repo. The results of any Gremlin query yielding a path can be visually examined. When executing such queries, a Graph tab appears next to the Console tab in the query results area. Gremlin queries can use by modulators to alter path result representations, and there are specific rules regarding how results are visually rendered, which are important to keep in mind.
For instance, in the first example below, the visualizer cannot ascertain the edge direction since the query lacks edge information:
g.V().hasLabel('airport').out().path().limit(5)
In contrast, the second query includes an outE
step, allowing the visualizer to determine the edge direction:
g.V().hasLabel('airport').outE().inV().path().limit(5)
When no by modulators are used, the visualizer labels the diagram elements with their respective vertex and edge labels. However, when by modulators are involved, it may not always be clear which elements are vertices or edges. For example:
g.V().hasLabel('airport').outE().inV().path().by('code').by('dist').limit(5)
In such cases, the visualizer may need additional hints to correctly depict the desired diagram.
Query Visualization Hints
You can provide query visualization hints using either -p
or --path-pattern
following the %%gremlin
cell magic. The general syntax is:
%%gremlin -p | --path-pattern <comma-separated hints>
The hint names correspond to common Gremlin steps used for traversing between vertices, and they should align with the steps in your query. The hints can be any combination from the following list, without spaces between commas:
- v
- inv
- outv
- e
- ine
- oute
For example, to add hints to the previous query, you could write:
%%gremlin -p v,oute,inv
g.V().hasLabel('airport').outE().inV().path().by('code').by('dist').limit(5)
Running the query with and without hints will highlight the differences. Without hints, the visualizer defaults to a vertex for the dist property, lacking clarity.
Adjusting Visualization Layout and Settings
Further adjustments to the visualization can be made using the following commands, which we will explore towards the end of this article:
%graph_notebook_vis_options
%%graph_notebook_vis_options
Exploring Routes from Palm Springs with Gremlin
Now that we understand the basics, let’s write a Gremlin query to find 10 routes originating from Palm Springs (PSP) airport. Running this query will initially display results in text form on the Console tab. By selecting the Graph tab, we can view a visual representation.
You can manipulate the graph by dragging vertices (left-click) and zooming in or out using the + and – icons or the scroll wheel on your mouse. Panning the diagram is possible by clicking and dragging in an empty area. Hovering over a vertex reveals a pop-up with its label information. Right-clicking on the diagram provides options to copy or save it as a PNG file, which is useful for sharing.
Here’s the code for our query:
%%gremlin
g.V().has('airport','code','PSP').out().path().by('code').limit(10)
The initial console results are shown below.
(Insert screenshot of Console tab)
The results in the Graph tab can be viewed here.
(Insert screenshot of Graph tab)
While the diagram is visually appealing, it currently lacks direction indicators for the routes. This is because the query results do not provide sufficient directionality information for the visualizer. However, we can easily rectify this by adding a hint after the cell magic: %%gremlin -p v,inv
, indicating that a vertex leads to another vertex through an inbound edge.
For further reading on budgeting and altruism, consider checking out this post on how to manage finances effectively. For insights on job descriptions, visit the authoritative source at SHRM. In addition, if you’re interested in onboarding strategies, Training Industry offers excellent resources on scaling onboarding processes.
Leave a Reply